import React from 'react';
import { useLocation, useModel, connect } from 'umi';
import { Badge } from 'antd';
const Bread = ({ msgData }) => {
  const { initialState = {} } = useModel('@@initialState');
  const { menuList } = initialState.info;
  const location = useLocation();
  const pathList = location.pathname.split('/');
  const path = '/' + pathList.pop();
  const midPath = '/' + pathList[2];
  let title = '-';
  let icon = '';
  menuList &&
    menuList.forEach((item) => {
      if (item.url === path) {
        title = item.name;
        icon = item.icon;
      } else if (item.children) {
        item.children.forEach((x) => {
          if (x.url === path) {
            title = x.name;
            icon = item.icon;
            return;
          } else if (x.url === midPath && x.children) {
            x.children.forEach((y) => {
              if (y.url === path) {
                title = y.name;
                icon = item.icon;
                return;
              }
            });
          }
        });
      }
    });
  return (
    <div className="bread-x bgf">
      {icon}
      <span className="title-x">{title}</span>
      {msgData.unRead ? (
        <Badge count={msgData.unRead + ' 条'} className="ml10" />
      ): ''}
    </div>
  );
};

export default connect(({ dict }) => ({
  msgData: dict.msgData,
}))(Bread);
